package com.cn.servlet.book;

import com.cn.Dao.BookDao;
import com.cn.Dao.NewsinfoDao;
import com.cn.base.Util;
import com.cn.entity.BookInfo;
import com.cn.entity.BookUnion;
import com.cn.entity.UserInfo;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.print.Book;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@WebServlet(name = "CheckMyBookServlet")
public class CheckMyBookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("GBK");
        response.setCharacterEncoding("GBK");
        try {
            String bk=request.getParameter("bk");
            String yh=request.getParameter("yh");
            String dep=request.getParameter("dep");
            String state=request.getParameter("state");
            String title="某公司报刊订单表";
            BookDao bookDao=new BookDao();
            List<BookUnion> bookUnions=new ArrayList<>();
            bookUnions=bookDao.findAllUnionLike(Util.changeLike(bk),Util.changeLike(yh),Util.stringOfInt(dep),
                    Util.stringOfInt(state));
            request.getSession().setAttribute("bookUnions",bookUnions);
            request.getSession().setAttribute("title",title);
            request.getRequestDispatcher("view_my_order.jsp").forward(request, response);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {

            String title="某公司报刊订单表";
            BookDao bookDao=new BookDao();
            List<BookUnion> bookUnions=new ArrayList<>();
            UserInfo userInfo=(UserInfo)request.getSession().getAttribute("userInfo");
            bookUnions=bookDao.findAllByUser(userInfo.getUsername());
            request.getSession().setAttribute("bookUnions",bookUnions);
            request.getSession().setAttribute("title",title);
            request.getRequestDispatcher("view_my_order.jsp").forward(request, response);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
